new Vue({
    el: '#main-container',
    data: {
        pageInfo: {
            current: 1,
            size: 5
        },
        app: {
            platform: 0,
            forceUpdate: 0
        },
        active: false
    },
    methods: {
        select: function (pageNum, pageSize) {
            axios({
                url: '/manager/app/select',
                params: {
                    current: pageNum,
                    size: pageSize
                }
            })
                .then(response => {
                    this.pageInfo = response.data.data; // response.data: ResultBean  response.data.data: PageInfo
                });
        },

        save: function () {
            axios({
                url: '/manager/app/saveOrUpdate',
                method: 'post',
                data: this.app
            }).then(response => {
                if (response.data.code == 200) {
                    //更新表格
                    this.select(this.pageInfo.current, this.pageInfo.size);
                    this.app = {
                        platform: 0,
                        forceUpdate: 0
                    }
                }
                layer.msg(response.data.msg);
            });
        },

        toUpdate: function (app_id) {
            axios({
                url: '/manager/app/selectOne',
                params: {
                    id: app_id
                }
            }).then(response => {
                if (response.data.code != 200) {
                    layer.msg(response.data.msg);
                    return;
                }
                //弹消息框（app-update.html）
                layer.appVersion = response.data.data;  //app数据
                //打开layer的所在的页面
                let index = layer.open({
                    type: 2,  // 类型：0 消息框  2 iframe
                    title: '更新app',
                    content: '/manager/app/app-update.html',
                    area: ['60%', '80%'],
                    end: () => {
                        this.select(this.pageInfo.current(), this.pageInfo.size);  //查询最新数据
                    }
                });
            });
        },

        doDelete: function (app_id) {
            layer.msg('是否删除？', {
                time: 0, //无自动消失计时
                btn: ['是', '否'],
                yes: index => {
                    axios({
                        url: '/manager/app/delete',
                        params: {
                            id: app_id
                        }
                    }).then(response => {
                        //关闭当前msg窗口
                        layer.close(index);
                        layer.msg(response.data.msg);
                        //成功后刷新数据列表
                        if (response.data.code == 200) {
                            this.select(this.pageInfo.current, this.pageInfo.size);
                        }
                    });
                }
            });
        }
    },
    created: function () {
        this.select(this.pageInfo.current, this.pageInfo.size);
    }
});